package org.check.UI;

import java.awt.Color;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;

import org.check.loadProperties.LoadProperty;

import java.awt.event.ItemListener;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.awt.event.ItemEvent;

public class CourseTypeSelectPanel extends JPanel {

	private JComboBox comboBox;
	private String courseType;
	List<String> courseTypeName = new LinkedList<String>();
	List<String> courseTypeCode = new LinkedList<String>();

	/**
	 * Create the panel.
	 */
	public CourseTypeSelectPanel() {
		
		setLayout(null);
		setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
		setBackground(new Color(192, 192, 192));

		comboBox = new JComboBox();
		comboBox.addItemListener(new ItemListener() {

			public void itemStateChanged(ItemEvent e) {
				setCourseType(comboBox.getSelectedItem().toString());
			}
		});
		getComboBoxList();
		int defaultInx = 0;
		for(int i = 0; i < courseTypeName.size(); i++){
			String str = courseTypeName.get(i);
			if(str.equals("课程"))
				defaultInx = i;
			comboBox.addItem(str);
		}
		comboBox.setSelectedIndex(defaultInx);
		comboBox.setBounds(10, 10, 142, 21);
		add(comboBox);
	}

	public String getCourseType() {
		return courseType;
	}

	public void setCourseType(String courseType) {
		this.courseType = courseType;
	}
	
	public String getSelectedType(){
		int index = comboBox.getSelectedIndex();
		String code = courseTypeCode.get(index);
		return code;
	}
	
	public void getComboBoxList(){
		Properties courseProp = LoadProperty.loadCourseTypoProp();
		Iterator it=courseProp.entrySet().iterator();		
 		while(it.hasNext()){
 		    Map.Entry entry=(Map.Entry)it.next();
 		    Object key = entry.getKey();
 		    Object value = entry.getValue();
 		    courseTypeName.add(key.toString());
 		    courseTypeCode.add(value.toString());
 		}
		
	}

}
